package edu.gatech.cs2340.mule.tests;

import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import edu.gatech.cs2340.mule.model.Player;
import edu.gatech.cs2340.mule.model.Race;
import edu.gatech.cs2340.mule.model.TurnEngine;

public class CalculatePlayerOrderTest {
	
	TurnEngine turnEngine;
	Player player1;
	Player player2;
	Player player3;
	Player player4;
	
	@Before
	public void setUp() throws Exception {
		// Create players
		player1 = new Player(Color.YELLOW, "Keegan Nesbitt", new Race("Buzzite"));
		player2 = new Player(Color.RED, "Jim Bob", new Race("Buzzite"));
		player3 = new Player(Color.BLUE, "Flapper McFlaps", new Race("Buzzite"));
		player4 = new Player(Color.ORANGE, "Bonzo the Clown", new Race("Buzzite"));
		
		Player[] allPlayers = {player1, player2, player3, player4};
		
		turnEngine = new TurnEngine(allPlayers);
	}

	/**
	 * Test the calculate player order for all players with the same score
	 */
	@Test
	public void sameScoreTest() {
		turnEngine.calculatePlayerOrder();
		Player[] currentOrder = turnEngine.getPlayersInScoreOrder();
		
		Player[] expectedOrder = {player1, player2, player3, player4};
		Assert.assertArrayEquals("The Player order is incorrect", expectedOrder, currentOrder);
	}
	
	/**
	 * Test the calculate player order for all players with distinct scores
	 */
	@Test
	public void allDifferentScoreTest() {
		player1.setMoneyAmount(40);
		player2.setMoneyAmount(20);
		player3.setMoneyAmount(30);
		player4.setMoneyAmount(10);
		
		turnEngine.calculatePlayerOrder();
		Player[] currentOrder = turnEngine.getPlayersInScoreOrder();
		
		Player[] expectedOrder = {player4, player2, player3, player1};
		Assert.assertArrayEquals("The Player order is incorrect", expectedOrder, currentOrder);
	}
	
	/**
	 * Test the calculate player order for a mixture of the same and different scores
	 */
	@Test
	public void someSameSomeDifferentTest() {
		player1.setMoneyAmount(10);
		player2.setMoneyAmount(20);
		player3.setMoneyAmount(30);
		player4.setMoneyAmount(10);
		
		turnEngine.calculatePlayerOrder();
		Player[] currentOrder = turnEngine.getPlayersInScoreOrder();
		
		Player[] expectedOrder = {player1, player4, player2, player3};
		Assert.assertArrayEquals("The Player order is incorrect", expectedOrder, currentOrder);
	}

}
